package com.scs.application.core.query;

/**
 * @description:
 */
public class QueryContextHolder {

    private final static ThreadLocal<QueryContext> THREAD_LOCAL = new ThreadLocal<>();

    /**
     * 获取当前查询上下文
     *
     * @return
     */
    public final static QueryContext currentContext() {
        if (THREAD_LOCAL.get() == null) {
            QueryContext queryContext = new QueryContext();
            THREAD_LOCAL.set(queryContext);
        }
        return THREAD_LOCAL.get();
    }

    /**
     * 清除查询上下文对象，避免内存泄露
     */
    public final static void clear() {
        THREAD_LOCAL.remove();
    }


}
